<template>
  <!--- 待办 -->
  <view>
    <view v-if="taskList && taskList.length > 0">
      <view class="grid-body mt-30" v-for="(item, index) in taskList" :key="index">
        <view class="check grid-common">
          <view class="flex text">
            下发时间：<text>{{ item.createTime }}</text>
          </view>
          <view class="flex text">
            巡检类型：<text>{{ item.inspectionTypeLabel }}</text>
          </view>
          <view class="flex text">
            任务名称：<text>{{ item.taskName }}</text>
          </view>
          <view class="flex text bor-top flex-row-r-c">
            <view class="flex">
              <button class="info-btn" @click="deal(item)">详情</button>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view v-else>
      <Empty></Empty>
    </view>
  </view>
</template>

<script>
import Empty from '@/components/cu-empty/index.vue'
import { getTask } from '@/api/equipment/Inspection-new.js'
export default {
  name: 'have',
  components: {
    Empty
  },
  data() {
    return {
      taskList: [],
      pageNum: 1,
      pageSize: 10,
      isFinished: false,
      total: null
    }
  },
  onShow() {
    this.initData()
  },
  onPullDownRefresh() {
    this.initData()
  },
  onReachBottom() {
    this.pageNum++
    this.getItemList()
  },
  mounted() {
    this.initData()
  },
  methods: {
    reachBottom() {
      this.pageNum++
      this.getItemList()
    },
    initData() {
      this.taskList = []
      this.isFinished = false
      this.pageNum = 1
      this.total = null
      this.getItemList()
    },
    getItemList() {
      if (this.isFinished) {
        return
      }
      const data = {
        pageSize: this.pageSize,
        pageNum: this.pageNum
      }
      if (!this.total || this.total > this.taskList.length) {
        getTask(2, data)
          .then((res) => {
            if (this.pageNum === 1) {
              this.taskList = res.rows
            } else {
              this.taskList.push(...res.rows)
            }
            this.total = res.total
          })
          .finally(() => {
            uni.stopPullDownRefresh()
          })
      }
    },
    deal(item) {
      uni.navigateTo({
        url: '/pages/work/inspectTask/components/lookDetail?subTaskId=' + item.subTaskId
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.check {
  position: relative;

  .title {
    font-size: 34rpx;
    font-weight: 700;
  }

  .icon-style {
    width: 52rpx;
    height: 52rpx;
    margin-right: 20rpx;
  }

  .text {
    display: flex;
    color: #999;

    text {
      color: #333;
      display: inline-block;
    }
  }

  .bor-top {
    padding-top: 20rpx;
    border-top: 1px solid #d5d7e3;
  }
}
</style>
